package org.example.mylogin.controller;


import cn.hutool.crypto.digest.BCrypt;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.mylogin.common.Result;
import org.example.mylogin.dto.AdminLoginDTO;
import org.example.mylogin.entity.Admin;
import org.example.mylogin.service.AdminService;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author mylogin
 * @since 2024-04-14
 */
@RestController
@RequestMapping("/admin")
@Slf4j
public class AdminController {

    @Resource
    private AdminService adminService;



    @PostMapping("login")
    public Result login(@RequestBody AdminLoginDTO adminLoginDTO) {
        log.info("adminLoginDTO:{}", adminLoginDTO);


        String token = adminService.login(adminLoginDTO);
        return Result.success(token);
    }

    @GetMapping("info")//未过期获取匿名
    //@RequestHeader("Authorization") String token
    public Result getAdminInfo() {
        Admin admin = adminService.getAdminInfo();
        return Result.success(admin.getNickname());
    }

}













